<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">物料编码/料号</label>
        <el-input v-model="query.materialCode" clearable placeholder="物料编码/料号" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">料品名称</label>
        <el-input v-model="query.materialName" clearable placeholder="料品名称" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">物料描述</label>
        <el-input v-model="query.description" clearable placeholder="物料描述" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">规格</label>
        <el-input v-model="query.specification" clearable placeholder="规格" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <label class="el-form-item-label">单位(pcs、米、㎡)</label>
        <el-input v-model="query.unit" clearable placeholder="单位(pcs、米、㎡)" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="物料编码/料号" prop="materialCode">
            <el-input v-model="form.materialCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="料品名称" prop="materialName">
            <el-input v-model="form.materialName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="物料描述">
            <el-input v-model="form.description" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="规格">
            <el-input v-model="form.specification" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="单位(pcs、米、㎡)" prop="unit">
            <el-input v-model="form.unit" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="入库载具类型(托盘/xx工装车/大料箱/小料箱)">
            <el-input v-model="form.inboundContainerType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="分拣载具类型">
            <el-input v-model="form.pickingContainerType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="配送载具类型">
            <el-input v-model="form.deliveryContainerType" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="包装规格(长) mm">
            <el-input v-model="form.packageLength" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="包装规格(宽) mm">
            <el-input v-model="form.packageWidth" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="packageHeight">
            <el-input v-model="form.packageHeight" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="最小包装容量">
            <el-input v-model="form.minPackageQuantity" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="仓码(U9)">
            <el-input v-model="form.warehouseCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="仓库名称">
            <el-input v-model="form.warehouseName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="库区编码">
            <el-input v-model="form.storageZoneCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="库区名称">
            <el-input v-model="form.storageZoneName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="物料类别">
            <el-input v-model="form.materialCategory" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="物料类别名称">
            <el-input v-model="form.materialCategoryName" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="基础分类(1:原材料 2:半成品 3:备件 4:成品)">
            <el-input v-model="form.baseCategory" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="分拣模式(按单分拣/最小包规分拣)">
            <el-input v-model="form.pickingMethod" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="配送模式(按车间/产线/工位配送)">
            <el-input v-model="form.deliveryMethod" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="发料模式（BackFlush倒冲、OneTime一次性、Push推式、Pull拉式、Other其他）">
            <el-input v-model="form.distributionMethod" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="创建时间" prop="createdAt">
            <el-input v-model="form.createdAt" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="更新时间" prop="updatedAt">
            <el-input v-model="form.updatedAt" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <!-- <el-table-column type="selection" width="55" />
        <el-table-column prop="id" label="主键" /> -->
        <el-table-column prop="materialCode" label="物料编码/料号" />
        <el-table-column prop="materialName" label="料品名称" />
        <el-table-column prop="description" label="物料描述" />
        <el-table-column prop="specification" label="规格" />
        <el-table-column prop="unit" label="单位(pcs、米、㎡)" />
        <el-table-column prop="inboundContainerType" label="入库载具类型(托盘/xx工装车/大料箱/小料箱)" />
        <el-table-column prop="pickingContainerType" label="分拣载具类型" />
        <el-table-column prop="deliveryContainerType" label="配送载具类型" />
        <el-table-column prop="packageLength" label="包装规格(长) mm" />
        <el-table-column prop="packageWidth" label="包装规格(宽) mm" />
        <el-table-column prop="packageHeight" label="packageHeight" />
        <el-table-column prop="minPackageQuantity" label="最小包装容量" />
        <el-table-column prop="warehouseCode" label="仓码(U9)" />
        <el-table-column prop="warehouseName" label="仓库名称" />
        <el-table-column prop="storageZoneCode" label="库区编码" />
        <el-table-column prop="storageZoneName" label="库区名称" />
        <el-table-column prop="materialCategory" label="物料类别" />
        <el-table-column prop="materialCategoryName" label="物料类别名称" />
        <el-table-column prop="baseCategory" label="基础分类(1:原材料 2:半成品 3:备件 4:成品)" />
        <el-table-column prop="pickingMethod" label="分拣模式(按单分拣/最小包规分拣)" />
        <el-table-column prop="deliveryMethod" label="配送模式(按车间/产线/工位配送)" />
        <el-table-column prop="distributionMethod" label="发料模式（BackFlush倒冲、OneTime一次性、Push推式、Pull拉式、Other其他）" />
        <el-table-column prop="createdAt" label="创建时间" />
        <el-table-column prop="updatedAt" label="更新时间" />
        <!-- <el-table-column v-if="checkPer(['admin','materialBasicInfo:edit','materialBasicInfo:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column> -->
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudMaterialBasicInfo from '@/api/work/materialBasicInfo'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
// import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = { id: null, materialCode: null, materialName: null, description: null, specification: null, unit: null, inboundContainerType: null, pickingContainerType: null, deliveryContainerType: null, packageLength: null, packageWidth: null, packageHeight: null, minPackageQuantity: null, warehouseCode: null, warehouseName: null, storageZoneCode: null, storageZoneName: null, materialCategory: null, materialCategoryName: null, baseCategory: null, pickingMethod: null, deliveryMethod: null, distributionMethod: null, createdAt: null, updatedAt: null }
export default {
  name: 'MaterialBasicInfo',
  components: { pagination, crudOperation, rrOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: 'material_basic_info', url: 'api/materialBasicInfo', idField: 'id', sort: 'id,desc', crudMethod: { ...crudMaterialBasicInfo },
      optShow: {
        add: false,
        edit: false,
        download: true,
        del: false,
        reset: true
      }
    })
  },
  data() {
    return {
      permission: {
        add: ['admin', 'materialBasicInfo:add'],
        edit: ['admin', 'materialBasicInfo:edit'],
        del: ['admin', 'materialBasicInfo:del']
      },
      rules: {
        materialCode: [
          { required: true, message: '物料编码/料号不能为空', trigger: 'blur' }
        ],
        materialName: [
          { required: true, message: '料品名称不能为空', trigger: 'blur' }
        ],
        unit: [
          { required: true, message: '单位(pcs、米、㎡)不能为空', trigger: 'blur' }
        ],
        createdAt: [
          { required: true, message: '创建时间不能为空', trigger: 'blur' }
        ],
        updatedAt: [
          { required: true, message: '更新时间不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'materialCode', display_name: '物料编码/料号' },
        { key: 'materialName', display_name: '料品名称' },
        { key: 'description', display_name: '物料描述' },
        { key: 'specification', display_name: '规格' },
        { key: 'unit', display_name: '单位(pcs、米、㎡)' }
      ]
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
